from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon
from PyQt5.uic.properties import QtGui
from PyQt5 import QtGui
import PyQt5
import password_managment
from try_mysql import *
from PyQt5.uic import loadUiType
import cinema
import register
import delete_user
import Manage_Password
from movie_record_manage_ui import Ui_Movie_record
import sys
ui, _ = loadUiType('begin.ui')

class Begin_App(QMainWindow, ui):
    #定义构造
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.handle_buttons()
        self.menubar.setObjectName("menubar")
        self.menuHelp.setObjectName("menuHelp")
        self.login.setObjectName("login")
        self.exitlogin.setObjectName("exitlogin")
        self.actionexit.setObjectName("actionexit")
        self.password_manage.setObjectName("password_manage")
        self.login.setEnabled(False)
        self.exitlogin.setEnabled(False)
        self.actionexit.setEnabled(True)
        self.password_manage.setEnabled(True)
        self.menuHelp.triggered[QAction].connect(self.menuTriggered)
        self.lineEdit_2.setEchoMode(QLineEdit.Password)


    def handle_buttons(self):
        self.begin_login.clicked.connect(self.UserLogin)
        self.begin_regist.clicked.connect(self.UserRegister)
        self.forget_password.clicked.connect(self.Password_Forget)
        self.staff_manage.clicked.connect(self.Staff)


    def UserLogin(self):
        conn = get_conn()
        cur = conn.cursor()
        StaffNum=self.begin_staff_num.text()
        StaffPassword=self.lineEdit_2.text()
        if (StaffNum==""or StaffPassword==""):
            print(QMessageBox.information(self, "提醒", "员工号码与密码不得为空", QMessageBox.Yes, QMessageBox.Yes))
            return
        else:
            sql2 = "select * from user where StaffNum=%s and StaffPassword=%s "
            cur.execute(sql2, (StaffNum, StaffPassword))
            data = cur.fetchone()
            if data:
                self.Mainwindow= cinema.Cinema_App()
                self.close()
                self.Mainwindow.show()
                return
            else:
                print(QMessageBox.information(self, "提醒", "请输入正确的登陆密码", QMessageBox.Yes, QMessageBox.Yes))

    def UserRegister(self):
        self.user_register= register.Register_App()
        self.close()
        self.user_register.show()

    def Password_Forget(self):
        self.password = Manage_Password.Password_App()
        self.close()
        self.password.show()

    def menuTriggered(self, q):

        if (q.text() == "退出"):
            qApp = QApplication.instance()
            qApp.quit()
        return

    def Staff(self):
        self.staff = delete_user.Delete_App()
        self.close()
        self.staff.show()

def main():
    app = QApplication([])
    window = Begin_App()
    window.show()
    app.exec_()

if __name__ == '__main__':
    main()


